package club.gskj.gulimall.shoppingcart.vo;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * 购物车信息
 */
public class CartVo implements Serializable {

    /**
     * 商品项
     */
    private List<CartItemVo> items;

    /**
     * 商品数量
     */
    private Integer countNum;

    /**
     * 商品类型数量
     */
    private Integer countType;

    /**
     * 商品总价
     */
    private BigDecimal amount;

    /**
     * 减免价格
     */
    private BigDecimal reduce = new BigDecimal("0.00");

    public List<CartItemVo> getItems() {
        return items;
    }

    public void setItems(List<CartItemVo> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        int count = 0;
        if (items != null && items.size() > 0) {
            for (CartItemVo item : this.items) {
                count += item.getCount();
            }
        }
        return count;
    }

    public Integer getCountType() {
        int count = 0;
        if (items != null && items.size() > 0) {
            for (CartItemVo item : this.items) {
                count += 1;
            }
        }
        return count;
    }

    public BigDecimal getAmount() {
        BigDecimal amount = new BigDecimal("0");

        // 计算所有购物项价格总结
        for (CartItemVo item : this.items) {
            // 只计算选中 购物项的价格
            if (item.getCheck()) {
                BigDecimal totalPrice = item.getTotalPrice();
                amount = amount.add(totalPrice);
            }
        }
        // 减去优惠价格
        BigDecimal subtract = amount.subtract(this.reduce);
        return subtract;
    }

    public BigDecimal getReduce() {
        return reduce;
    }
}
